package com.sc.nft.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sc.nft.annotation.UserLogin;
import com.sc.nft.controller.request.IdRequest;
import com.sc.nft.entity.PrizeDrawActivityAwardLog;
import com.sc.nft.entity.dto.ActivityLogDTO;
import com.sc.nft.entity.vo.ActivityLogVO;
import com.sc.nft.entity.vo.RollVO;
import com.sc.nft.pool.UserPool;
import com.sc.nft.service.PrizeDrawActivityAwardLogService;
import com.sc.nft.sup.PageRequest;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 抽奖活动的奖品日志(PrizeDrawActivityAwardLog)表控制层
 *
 * @author wwc
 * @since 2023-08-23 17:21:50
 */

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("prizeDrawActivityAwardLog")
@Api(tags = "抽奖活动的奖品日志")
public class PrizeDrawActivityAwardLogController {

    /**
     * 服务对象
     */
    private final PrizeDrawActivityAwardLogService prizeDrawActivityAwardLogService;

    @PostMapping(value = "/activityLog", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "活动日志", notes = "活动日志", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public PageResult<ActivityLogVO> activityLog(@RequestBody ActivityLogDTO activityLogDTO) {
        IPage<PrizeDrawActivityAwardLog> prizeDrawActivityAwardLogIPage = prizeDrawActivityAwardLogService.activityLog(activityLogDTO, UserPool.getUser());
        return PageResult.success(prizeDrawActivityAwardLogIPage.convert(prizeDrawActivityAwardLog -> {
            ActivityLogVO activityLogVO = new ActivityLogVO();
            BeanUtil.copyProperties(prizeDrawActivityAwardLog, activityLogVO);
            return activityLogVO;
        }));
    }

    @PostMapping(value = "/roll", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "滚动数据", notes = "滚动数据", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result<List<RollVO>> roll(@RequestBody IdRequest idRequest) {
        return Result.success(prizeDrawActivityAwardLogService.roll(idRequest.getId()));
    }

}
